<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <!--          <a-col :md="4" :sm="12">
                      <a-form-item label="面料编号">
                        <a-input placeholder="请输入面料编号" v-model="queryParam.fabricCode"></a-input>
                      </a-form-item>
                    </a-col>

                    <a-col :md="4" :sm="12">
                      <a-form-item label="供应商">
                        <a-input placeholder="请输入供应商编号" v-model="queryParam.gysCode" style="width: 100%"></a-input>
                      </a-form-item>
                    </a-col>

                    <a-col :md="4" :sm="12">
                      <a-form-item label="销售状态">
                        <a-select placeholder="请选择销售状态" style="width: 100%" v-model="queryParam.status">
                          <a-select-option value="0">
                            上架中
                          </a-select-option>
                          <a-select-option value="2">
                            已下架
                          </a-select-option>
                          <a-select-option value="1">
                            已删除
                          </a-select-option>
                        </a-select>
                      </a-form-item>
                    </a-col>-->

          <a-col :md="4" :sm="12">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<!--              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button :href="exportFabric" style="margin-left: 8px" type="primary" icon="export">下载模板</a-button>
              <a-upload style="margin-left: 8px" name="file" :showUploadList="false"
                        :multiple="false"
                        :customRequest="myupload"
                        :action="importExcelUrl" @change="handleImportExcel">
                <a-button type="primary" icon="import"><upload-outlined/>导入</a-button>
              </a-upload>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!--table区域-begin-->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="30px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a-menu-item  style="display: inline;margin-left: 10px">
                  <a-popconfirm title="确定删除吗?" @confirm="() => delFunc(record.bookandid)">
                    <a style="color:deepskyblue">删除</a>
                  </a-popconfirm>
          </a-menu-item>
        </span>
      </a-table>
    </div>

  </a-card>

</template>

<script>
import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import JDate from '@/components/jeecg/JDate.vue'
import {getAction, postAction} from "../../api/manage";
import {UploadOutlined} from '@ant-design/icons-vue';

export default {
  name: 'Fabric',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
    UploadOutlined
    // LgyxCreditRateModal
  },
  data() {
    return {
      visible: false, // 新增弹框的显示
      description: '面料订单',
      fabricOrderDetail: [], // 当前的面料订单详情
      fabricDetail: {}, // 面料详情
      orderDetail: {}, // 订单详情
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '面料编号',
          align: "center",
          dataIndex: 'fabricCode'
        },
        {
          title: '供应商面料编号',
          align: "center",
          dataIndex: 'gysfabriccode'
          /* customRender: (text) => {
             //字典值替换通用方法
             return filterDictTextByCache('sex', text);
           }*/
        },
        {
          title: '面料缩略图',
          align: "center",
          dataIndex: 'fabricImg',
          scopedSlots: {customRender: 'imgSlot'}
        },
        /*{
          title: '零剪价（元/米）',
          align: "center",
          dataIndex: 'price'
        },
        {
          title: '库存（米）',
          align: "center",
          dataIndex: 'inventory'
        },*/
        {
          title: '品牌',
          align: "center",
          dataIndex: 'pingpai'
        },
        /*{
          title: '面料组',
          align: "center",
          dataIndex: 'groupName'
        },
        {
          title: '销售状态',
          align: "center",
          dataIndex: 'status',
          customRender: function (text) {
            if (text == '0') {
              return '上架中'
            } else if (text == '2') {
              return '已下架'
            } else if (text == '1') {
              return '已删除'
            }
          }
        },*/
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          // fixed:"right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: '/fabricCenter/listFabricFromBooklet' + '?bookletid=' + this.$route.query.booklet, // 面料列表
        importExcelUrl: "/fabricCenter/importBookFabricExcel", // 导入Excel
        delFabricFrombook: "/fabricCenter/delFabricFrombook", // 删除面料
        exportFabric: "fabricCenter/exportFabric", // 导出Excel
      },
      dictOptions: {},
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    exportFabric: function () {
      return `${window._CONFIG['domianURL']}/${this.url.exportFabric}`
    }
  },
  methods: {
    /**
     * 删除面料
     */
    delFunc(id) {
      getAction(this.url.delFabricFrombook, {'id': id}).then(res => {
        if (res.code == 200) {
          this.$message.success("操作成功")
          this.loadData()
        }
      })
    },

    // 导入面料excel
    myupload(data) {
      let fdata = new FormData()
      fdata.append('file', data.file)
      fdata.append('booklet', this.$route.query.booklet)
      postAction(this.url.importExcelUrl, fdata).then(res => {
        if (res.code == '0') {
          this.$message.success("导入成功")
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    },

    initDictConfig() {
    }
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';

.fabricName {
  margin-left: 10px;
  margin-top: 10px;
  width: auto;
  display: block !important;
  background: #2d2d2d;
  color: #ffe56d;
  text-align: center;
  border-radius: 3px;
}

.fabigtitle {
  height: 34px;
  width: 200px;
  text-align: left;
}

.fabigcontent {
  height: 34px;
  width: 200px;
  text-align: right;
}

.fatitle {
  height: 34px;
  width: 82px;
  background: rgb(242 242 242);
  text-align: center;
}

.facontent {
  width: 180px;
  overflow: hidden;
  text-align: center;
}
</style>